package com.example.demozmq.controller;

import java.util.HashMap;
import java.util.Map;

public class TestComputeIfAbsent {

    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("apple", 1);
        map.put("banana", 2);

        int orangeCount = map.computeIfAbsent("orange", k -> 0);
        System.out.println(orangeCount); // 输出 0

        int appleCount = map.computeIfAbsent("apple", k -> 0);
        System.out.println(appleCount); // 输出 1
    }

}
